var exec = require('child_process').exec;

var apkHelper = {
	getMessage(upload_url, cb) {
		//var upload_url = '0ca3b480-ab62-11e8-936c-e3afec8d550d.1';
		var cmdStr = '/work/adb/android-8.1.0/aapt dump badging /work/know/know_pc/upload/' + upload_url;
		exec(cmdStr, function(err, stdout, stderr) {
			if (err) {
				console.log('get weather api error:' + stderr);
			} else {
				var packageName = stdout.split('=')[1];
					packageName = packageName.split(' ')[0];
					packageName = packageName.replace(/[\'\"\\\/\b\f\n\r\t]/g, '');
				var versionCode = stdout.split('=')[2];
					versionCode = versionCode.split(' ')[0];
					versionCode = versionCode.replace(/[\'\"\\\/\b\f\n\r\t]/g, '');
				var versionName = stdout.split('=')[3];
					versionName = versionName.split(' ')[0];
					versionName = versionName.replace(/[\'\"\\\/\b\f\n\r\t]/g, '')

				var message = {
					packageName: packageName,
					versionCode: versionCode,
					versionName: versionName
				}
				console.log("message::", message);
				cb(message);
			}
		});
	}
}

module.exports = apkHelper;